package com.example.test;

import com.example.config.MySpringConfig;
import com.example.service.UserService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @Description:加载对象通过扫包范围 spring 容器中对象默认是单例的;使用 @Scope("prototype") 设置对象为 多例，@Scope("singleton") 为单例
 * @Author: mingtian
 * @CreateDate: 2019/12/6 10:49
 * @Version: 1.0
 */
public class BeanTest05 {

    /**
     * 加载配置类
     */
    private static AnnotationConfigApplicationContext applicationContext;

    public static void main(String[] args) {
        applicationContext = new AnnotationConfigApplicationContext(MySpringConfig.class);
        //注解方式加载类  spring 容器中对象默认是单例的
        UserService userService1 = applicationContext.getBean("userService", UserService.class);
        UserService userService2 = applicationContext.getBean("userService", UserService.class);

        System.out.println(userService1 == userService2);

    }
}